package server;

import java.io.File;
import java.util.HashMap;
import servlet.*;
//Server的上下文信息，主要就是服务器相关的信息，以及解析项目中web.xml文件生成Servlet搜索树
public class ServerContext {
	private String ServerRootPath;
	private HashMap<String,MySession> sessionContainer;
	private static ServerContext serverContext = null;
	private ServletMappingTree servletMappingTree;
	private String jspRootPath;
	
	private ServerContext(WebServer webServer) {
		ServerRootPath = System.getProperty("user.dir");
		sessionContainer = new HashMap<String,MySession>();
		File ProjectRoot = new File(ServerRootPath+"\\webapps");
		File[] projects = ProjectRoot.listFiles();
		servletMappingTree = new ServletMappingTree();
		servletMappingTree.buildTree(projects);
		jspRootPath = ServerRootPath + "/work/pku/ss/jsp";
	}
	
	public static ServerContext getInstance(WebServer webServer){
		if(serverContext==null){
			serverContext = new ServerContext(webServer);
		}
		return serverContext;
	}

	public String getServerRootPath() {
		return ServerRootPath;
	}

	public HashMap<String, MySession> getSessionContainer() {
		return sessionContainer;
	}

	public ServletMappingTree getServletMappingTree() {
		return servletMappingTree;
	}
	
	

}
